﻿using B.S.BasicData.Domain;
using B.S.BasicData.ErrorCode;
using B.S.BasicData.Infrastructure.Interfance;
using B.S.BasicData.Read.Apilication.Common.Menu;
using MediatR;

namespace B.S.BasicData.Read.Apilication.Handler.Menu
{
    public class GetmenuParmentHandler : IRequestHandler<GetmenuParmentCommon, ApiResult<List<menuModel>>>
    {
        private readonly IBaseRepository<menuModel> menuRepo;

        public GetmenuParmentHandler(IBaseRepository<menuModel> menuRepo)
        {
            this.menuRepo = menuRepo;
        }
        //
        public Task<ApiResult<List<menuModel>>> Handle(GetmenuParmentCommon request, CancellationToken cancellationToken)
        {
            ApiResult<List<menuModel>> res = new ApiResult<List<menuModel>>();

            var info = menuRepo.GetAll().Where(x=>x.ParentId==request.MenuId);

            if (info.Count()>0)
            {
                res.Code=ApiEnum.Success;
                res.Message = "有子集";
                return Task.FromResult(res);
            }
            else
            {
                res.Code = ApiEnum.Error;
                res.Message = "没有子集";
                return Task.FromResult(res);
            }
        }
    }
}
